package com.zj.leetcode.medium;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: algorithm
 * @description:
 * @author: Zhang Bo
 * @create: 2022-01-13 14:26
 **/
public class EncodeAndDecodeTinyurl{
    public static void main(String[] args) {
//        Solution solution = new EncodeAndDecodeTinyurl().new Solution();

    }
    //leetcode submit region begin(Prohibit modification and deletion)
    public class Codec {

        private Map<String, String> short2Long = new HashMap<>();

        // Encodes a URL to a shortened URL.
        public String encode(String longUrl) {
            String hash = longUrl.hashCode() + "";
            short2Long.put(hash, longUrl);
            return "http://tinyurl.com/" + hash;
        }

        // Decodes a shortened URL to its original URL.
        public String decode(String shortUrl) {
            String sh = shortUrl.substring(shortUrl.lastIndexOf("/") + 1);
            return short2Long.get(sh);
        }
    }

// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.decode(codec.encode(url));
//leetcode submit region end(Prohibit modification and deletion)

}
